package com.zmxtea.shop.controller;

import com.zmxtea.shop.entity.response.Response;
import com.zmxtea.shop.service.GoodsRepository;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Author: zhyx
 * Date:2017/10/20
 * Time:14:08
 */
@RestController
@RequestMapping(value = "/goods")
public class GoodsController {
    private static Logger logger = LoggerFactory.getLogger(GoodsController.class);
    @Autowired
    private GoodsRepository goodsRepository;

    @ResponseBody
    @RequestMapping(value = "/find/findall", produces = "application/json", method = RequestMethod.POST)
    public Response findAll() {
        return new Response().setResult(goodsRepository.findAll());
    }

    @ResponseBody
    @RequestMapping(value = "/find/findbyid", produces = "application/json", method = RequestMethod.POST)
    public Response findById(@RequestAttribute Integer id) {
        logger.info("参数：id={}", id);
        return new Response().setResult(goodsRepository.findById(id));
    }

}
